package br.com.locautowebbd.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;

public class JDBCConnectionUtil {

	private static Connection conexao = null;

	//private static String nomeDriver = "org.hsqldb.jdbcDriver";
	//private static String url = "jdbc:hsqldb:hsql://localhost/baseBanco";
	
	private static String nomeDriver = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:oracle:thin:@localhost:1521:xe";
	private static String login = "alexsandro";
	private static String senha = "123";
	
	

	private static void abrirConexao() throws SQLException, ClassNotFoundException {
		if (conexao == null || conexao.isClosed()) {
			Class.forName(nomeDriver);
			conexao = DriverManager.getConnection(url, login, senha);
			System.out.println("Conexao aberta com sucesso");
		}
	}

	public static Connection obterConexao()throws SQLException {
		if (conexao == null || conexao.isClosed()) {
			try {
				abrirConexao();
			} catch (ClassNotFoundException ex) {
				throw new SQLException(ex.getMessage());
			}
		}
		return conexao;
		
	}

	
}